local info1 = require '地图.游戏流程.天赋抽取.天赋效果'
local func2 = require '地图.游戏流程.天赋抽取.组合效果'
local func1 = info1.func
local tips1 = info1.tips
local jb_list = load_excel('天赋设定.xlsx','组合效果')

for name,data in pairs(jb_list) do
    local tips = data.tip:split('：')
    local text = tips[1]:gsub('，','\n')
    if func2[name]==nil then
        data.state = text_unpack_attrs(text,true)
        if #data.state==0 then
            print('没有处理',name)
        end
    end
    
    data.tip = data.tip:gsub('([%d]+)([\0%%]?)',function(num,ex)
        return ('|cff00ff00%s%s|r'):format(num,ex)
    end)
end

local tf_list = {}
local group = {}
ac.tf_list = tf_list
local frames = {
    [[羁绊卡牌\色框\蓝.blp]],
    [[羁绊卡牌\色框\紫.blp]],
    [[羁绊卡牌\色框\黄.blp]],
    [[羁绊卡牌\色框\红.blp]],
}
for a,data in pairs(load_excel('天赋设定.xlsx','天赋数据')) do
    local name = data.name
    local tips = data.tip
    local lv = data['等级']
    data.index = a
    --边框路劲
    data.frame_art = frames[lv] or frames[1]

    --属性读取
    local text = tips:gsub('，','\n')
    if func1[name]==nil then
        data.state = text_unpack_attrs(text)
        if #data.state==0 then
            print('没有处理',name)
        end
    end

    --组合
    local jb = data['组合名称']
    data.show_class = jb
    data.ts_tip = function(self)
        return ('%s|n|n%s'):format(self.title or self.name,format_obj(self,self.tip))
    end
    if jb and jb~='' then
        local jb_data = jb_list[jb]
        if jb_data then
            if group[jb]==nil then
                group[jb] = {}
            end
            data.show_class_name = jb_data.title or jb
            data.jb_list = group[jb]
            data.jb_tip = ('|cffff00ff组合效果|r|n%s'):format(jb_data.tip)
            data.jb_tip2 = jb_data['加入卡池'] or ''
            table.insert(group[jb],name)

            data.jb_title = function(self)
                local has = ac.player.self:get_data('天赋拥有表')
                local jb_list = self.jb_list
                local max = 0
                local num = 0
                if has and jb_list then
                    for _,name in ipairs(jb_list) do
                        max = max + (tf_list[name]['数量'] or 1)
                        num = num + (has[name] or 0)
                    end
                end
                return ('%s|cff999999(%d/%d)|r'):format(jb_data.title or jb,num,max)
            end
        else
            print('没有找到组合效果',name,jb)
        end
    else
        data.jb_title = '|cffffff00通用|r'
        if data['数量'] then
            data.jb_tip = ('|cffff00ff组合效果|r|n该卡牌最多获取|cff00ff00%0.f|r次'):format(data['数量'])
        else
            data.jb_tip = '|cffff00ff组合效果|r|n该卡牌可以无限选取'
        end
    end
    data['数量'] = tonumber(data['数量']) or 999
    tips = tips:gsub('([%d]+)([\0%%]?)',function(num,ex)
        return ('|cff00ff00%s%s|r'):format(num,ex)
    end)
    data.base_tip = tips1[name] or tips
    data.tip = [['base_tip'|n|n|n'jb_tip']]
    data.art = data.art or [[ReplaceableTextures\CommandButtons\BTNMarkOfFire.blp]]
    tf_list[name] = data
end





ac.wait(10,function()
    local test_data = load_excel('天赋设定.xlsx','天赋数据')
    ac.game:notify('测试-注册数据','天赋测试',test_data,function(_,player,name)
        local hero = player.hero
        
        hero:notify('天赋-获得属性',hero,tf_list[name])
    end)

end)



return {
    tf_list = tf_list,
    jb_list = jb_list,
    group = group,
    func1 = func1,
    func2 = func2,
}






